"use strict";
require("test").setup();

var Coroutine = require('coroutine');
var hash = require('hash');

describe("log", function() {
    before(function() {

    });

    after(function() {
        clearDB();
    });


    it("登录", function() {
        httpPost("GET", "/v1.0/api/user/Sync", {})

        var t = "123"
        var result = httpPost("POST", "/v1.0/api/user/WebLogin", {
            "phone": "18888888888",
            "password": hash.md5(hash.md5("ZHYQ2022").digest().hex() + t).digest().hex(),
            "t": t,
        })

        assert.equal(result.code, "200");
        assert.equal(result.data.id, 2);
        assert.equal(result.data.role, "超级管理员");
        assert.equal(result.data.edited_password, true);

        result = httpPost("POST", "/v1.0/api/user/WebLogin", {
            "phone": "18888888888",
            "password": hash.md5(hash.md5("ZHYQ2022").digest().hex() + t).digest().hex(),
            "t": t,
        })

        assert.equal(result.code, "200");
    });

    it("登录日志", function() {
        var t = "123"
        var result = httpPost("POST", "/v1.0/api/log/List", {
            "page": 1,
            "limit": 10,
        })

        assert.equal(result.code, "200");
        assert.equal(result.data.list.length, 2);
        assert.equal(result.data.total, 2);
        assert.equal(result.data.list[0].id, 2);
        assert.equal(result.data.list[0].user_id, 1);
        assert.equal(result.data.list[0].user_name, "超级管理员");
        assert.equal(result.data.list[0].ip, "127.0.0.1");
        assert.equal(result.data.list[0].platform, "后台 Web");
        // assert.equal(result.data.list[0].device, "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.98 Safari/537.36");
        assert.equal(result.data.list[0].module, "user");
        check_result(result.data.list[0].content, {
            "action": "登录"
        })
        assert.equal(result.data.list[1].id, 1);
    });
});

require('test').run();